<?php
$SITEROOT = '../';
include_once($SITEROOT . 'assets/snippets/shoppingCart/dbconfig.inc.php');
include_once($SITEROOT . 'assets/snippets/shoppingCart/kiwee.class.php');

$kiwee = new Kiwee();

if(IN_MANAGER_MODE!="true") die('<b>' . $_lang['kiwee_include_order_error'] . '</b>');
if ($_SESSION['mgrPermissions']['settings'] != "1") { echo 'Insufficient permissions for this module.'; exit; }

$theme = $manager_theme ? "$manager_theme/":"";
$modx->manager->initPageViewState();

// get and save search string
if($_REQUEST['op']=='reset') {
	$sqlQuery = $query = '';
	$_PAGE['vs']['search']='';
}
else {
	$sqlQuery = $query = isset($_REQUEST['search'])? $_REQUEST['search']:$_PAGE['vs']['search'];
	if(!is_numeric($sqlQuery)) $sqlQuery = mysql_escape_string($query);
	$_PAGE['vs']['search'] = $query;
}

// get & save listmode
$listmode = isset($_REQUEST['listmode']) ? $_REQUEST['listmode']:$_PAGE['vs']['lm'];
$_PAGE['vs']['lm'] = $listmode;
?>
<div id="overlay" onclick="hideBox()" style="display:none"></div>
	<div id="box" style="display:none">
	    <img style="position: absolute; top: -5px; right: 35px; cursor: pointer;" src="js/modal_window/images/pdf.gif" onclick="hideBox()" alt="PDF Version" title="High-Quality PDF Version" />
	    <img style="position: absolute; top: -5px; right: 15px; cursor: pointer;"  src="js/modal_window/images/print.gif" onclick="hideBox()" alt="Quick Print" title="Quick Print" />
	    <img style="position: absolute; top: -5px; right: -5px; cursor: pointer;"  src="js/modal_window/images/close.gif" onclick="hideBox()" alt="Close" title="Close this Window" /><br />
	    <div style="margin: 5px 0 5px 0; width: 100%; text-align: center; color: #ff9933; font-weight: bold; font-size: 18px;">Order Details</div><div style="clear:both;" />
	    <div id="inner-box"></div>
	</div>
</div>
<script type="text/javascript" src="js/prototype.js"></script>
<script type="text/javascript" src="js/modal_window/javascripts/modal.js"></script>
<script type="text/javascript" src="actions/includes/interface.js"></script>
<link href="js/modal_window/stylesheets/modal.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">
    function orders_properties(id){
	    makePOSTRequest('actions/ajax.php', "trxntype=orders_properties&id=" + id, 'orders_properties');
	}
	//added by Bright @ 20080806
    function order_gridload(){
		var poststr = "trxntype=orders_gridload&sortordersby=ALLORDERS";
        makePOSTRequest('actions/ajax.php', poststr, 'orders_gridload');
    }	
	
    function updateordergrid(){
        var poststr = "trxntype=orders_gridload&sortordersby=" + urival('filterbydropdown');
        makePOSTRequest('actions/ajax.php', poststr, 'orders_gridload');
    }
	
	function searchResource(){
        document.resource.op.value="srch";
        document.resource.submit();
    };

    function resetSearch(){
        document.resource.search.value = ''
        document.resource.op.value="reset";
        document.resource.submit();
    };

    function changeListMode(){
        var m = parseInt(document.resource.listmode.value) ? 1:0;
        if (m) document.resource.listmode.value=0;
        else document.resource.listmode.value=1;
        document.resource.submit();
    };
	
	function uorderstatus_update(id) {
		var poststr = "id=" + id + "&status=" + urival('uordstatus') + "&trxntype=orderstatus_update";
		makePOSTRequest('actions/ajax.php', poststr, 'orders_gridload');
		hideBox();
	}

	
	function ajaxrendercomponent(name) {
        if (http_request.responseText.substring(0, 5) == "ERROR") {
             alert(http_request.responseText);
        } else if (name == 'orders_properties'){ document.getElementById('inner-box').innerHTML=http_request.responseText; 
			document.getElementById('inner-box').style.margin='20px'; 
			document.getElementById('box').style.width='600px';
		   	document.getElementById('box').style.left='27%'; 
			showBox(); 
		} else if (name == 'orders_gridload'){ 
			document.getElementById('ordermaintenancegrid').innerHTML=http_request.responseText; 
		} else {
			alert(name);
		}
	}
	order_gridload();
</script>
<link href="actions/includes/kiwee.css" rel="stylesheet" type="text/css" />
<div class="kiwee-msc" id="mascot"><a href="http://www.kiweecommerce.org"><img src="actions/includes/Kiwee-small.gif" /></a></div>		
<div class="subTitle">
<span class="right"></span>
</div>
<div class="sectionHeader"><?php echo $_lang["order_aag_header"]; ?></div>
<div class="sectionBody">
	<p><?php echo $_lang['order_aag_detail']; ?></p>

<table border=0 cellspacing=0 cellpadding=0 align=center class="grid">
	<tr class="gridHeader" align=center><td colspan=8><b>Orders Summary</b></td></tr>
	<tr class="sectionHeader">
		<td><b>&nbsp;&nbsp;&nbsp;New&nbsp;&nbsp;&nbsp;&nbsp;</b></td>
		<td><b>&nbsp;&nbsp;&nbsp;Processing&nbsp;&nbsp;&nbsp;&nbsp;</b></td>
		<td><b>&nbsp;&nbsp;&nbsp;Shipped&nbsp;&nbsp;&nbsp;&nbsp;</b></td>
		<td><b>&nbsp;&nbsp;&nbsp;Updated&nbsp;&nbsp;&nbsp;&nbsp;</b></td>
		<td><b>&nbsp;&nbsp;&nbsp;Backorders&nbsp;&nbsp;&nbsp;&nbsp;</b></td>
		<td><b>&nbsp;&nbsp;&nbsp;Cancelled&nbsp;&nbsp;&nbsp;&nbsp;</b></td>
		<td><b>&nbsp;&nbsp;&nbsp;Errors&nbsp;&nbsp;&nbsp;&nbsp;</b></td>
		<td><b>&nbsp;&nbsp;&nbsp;Total&nbsp;&nbsp;&nbsp;&nbsp;</b></td>
	</tr>
<?php
	$orderstat = $kiwee->getOrderStats();
    echo '<tr><td align=center>' . $orderstat['neworders'] . '</td>';
    echo '<td align=center>' . $orderstat['processedorders'] . '</td>';
    echo '<td align=center>' . $orderstat['shippedorders'] . '</td>';
    echo '<td align=center>' . $orderstat['updatedorders'] . '</td>';
    echo '<td align=center>' . $orderstat['backorders'] . '</td>';
    echo '<td align=center>' . $orderstat['cancelledorders'] . '</td>';
    echo '<td align=center>' . $orderstat['errororders'] . '</td>';
    echo '<td align=center>' . $orderstat['totalorders'] . '</td></tr>';
?>
</table>
</div>
<div class="sectionHeader"><?php echo $_lang["order_maintenance_header"]; ?></div>
<div class="sectionBody">
	<p><?php echo $_lang['order_maintenance_detail']; ?></p>
    <div class="searchbar">
		<div><?php echo $_lang["import_filterby"]; ?> </div>
		<div><select onchange="updateordergrid()" id="filterbydropdown">
			<option value="ALLORDERS">All</option>
			<option value="NEWORDERS">New</option>
			<option value="CANCELLEDORDERS">Cancelled</option>
			<option value="SHIPPEDORDERS">Shipped</option>
			<option value="ERRORORDERS">Errors</option>
			<option value="PROCESSORDERS">Processing</option>
			<option value="UPDATED">Updated</option>
			<option value="BACKORDERED">Back Ordered</option>
		</select></div>
        <!--<td><a href="#" class="" title="<?php echo $_lang["search"];?>" onclick="searchResource();return false;"><?php echo $_lang["go"]; ?></a></td>-->
        <!--<td><a href="#" class="" title="<?php echo $_lang["reset"];?>" onclick="resetSearch();return false;"><img src="media/style/<?php echo $manager_theme ? "$manager_theme/":""; ?>images/icons/refresh.gif" width="16" height="16"/></a></td>-->
       <!--<td><a href="#" class="" title="<?php echo $_lang["list_mode"];?>" onclick="changeListMode();return false;"><img src="media/style/<?php echo $manager_theme ? "$manager_theme/":""; ?>images/icons/table.gif" width="16" height="16"/></a></td>-->
	</div>
<div>
<br />
<!--edited by Bright @ 20080806 -->
<div id="ordermaintenancegrid" name="ordermaintenancegrid"></div>
</div>
	
